package com.xxxx.server.exception;

import com.xxxx.server.vo.RespBean;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;

/**
 * @description: 全局异常处理
 * @author: Wy
 * @create: 2021-11-23 14:46
 **/
//@RestControllerAdvice
public class GlobalException {

    @ExceptionHandler(SQLException.class)
    public RespBean mySQLException(SQLException e){
        if (e instanceof SQLIntegrityConstraintViolationException){
            return new RespBean().error("该数据有关联数据，操作失败！");
        }
        return new RespBean().error("数据库操作异常！");
    }
}
